package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeptDto;
import com.zzyl.service.DeptService;
import com.zzyl.vo.DeptVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//将该类直接交给Spring进行管理
@RestController
//主路径
@RequestMapping("/dept")
//告诉前端该类的作用
@Api("部门管理")
public class DeptController {

    @Autowired
    private DeptService deptService;
    @PostMapping("/list")
    @ApiOperation(value = "部门列表查询")
    @ApiImplicitParam(name = "deptDto", value = "部门列表的参数",required = false,dataType = "DeptDto")
    @ApiOperationSupport(includeParameters = {
            "deptDto.dataState",
            "deptDto.deptName",
            "deptDto.parentDeptNo"
    })
   /* public ResponseResult< List<DeptVo>> list(@RequestBody DeptDto deptDto){
      List<DeptVo> deptVoList  =  deptService.getList(deptDto);
        return ResponseResult.success(deptVoList);
    }*/
    public ResponseResult< List<DeptVo>> list(@RequestBody DeptDto deptDto){
        List<DeptVo> deptVoList  =  deptService.getList(deptDto);
        return ResponseResult.success(deptVoList);
    }
    //树形结构选择
    @ApiOperation(value="树形结构选择")
    @PostMapping("/tree")
    public ResponseResult<TreeVo> deptTree(){
        TreeVo treeVo = deptService.deptTree();
        return ResponseResult.success(treeVo);
    }
@ApiOperation(value="部门添加",notes="添加部门")
@ApiImplicitParam(name= "deptDtto",value = "部门DTO对象",required=true,dataType="DaptDto")

//这个可以理解为使用DeptDTO里面的几个参数
@ApiOperationSupport(includeParameters = {
        "deptDto.dataState",
        "deptDto.deptName",
        "deptDto.parentDeptNo",
        "deptDto.sortNo",
        "deptDto.leaderId",
        "deptDto.leaderName",

})
    public ResponseResult<DeptVo>  createDept(@RequestBody DeptDto deptDto){

    return ResponseResult.success(deptService.insert(deptDto));
}
}
